'use strict';

goog.provide('Blockly.Blocks.JoyRobot');

goog.require('Blockly.Blocks');


Blockly.Blocks.JoyRobot.HUE = 120;


var JOYROBOT_DIRECTION=[[Blockly.JOYROBOT_DIRECTION_FORWARD, "1"],[Blockly.JOYROBOT_DIRECTION_BACK, "2"],[Blockly.JOYROBOT_DIRECTION_STOP,"5"],[Blockly.JOYROBOT_DIRECTION_TURNLEFT, "3"],[Blockly.JOYROBOT_DIRECTION_TURNRIGHT, "4"]];
var JOYROBOT_CONTROLMODE=[[Blockly.JOYROBOT_CONTROLMODE_BLUETOOTH,"0"],[Blockly.JOYROBOT_CONTROLMODE_REMOTE,"1"],[Blockly.JOYROBOT_CONTROLMODE_IRTRACKING,"2"],[Blockly.JOYROBOT_CONTROLMODE_IRAVOIDANCE,"3"],[Blockly.JOYROBOT_CONTROLMODE_LIGHTFIND,"4"],[Blockly.JOYROBOT_CONTROLMODE_ULTRASONICAVOIDANCE,"5"],[Blockly.JOYROBOT_CONTROLMODE_PS2,"6"],[Blockly.JOYROBOT_CONTROLMODE_NRF24L01,"7"],[Blockly.JOYROBOT_CONTROLMODE_ULTRASONICIRAVOIDANCE,"8"],[Blockly.JOYROBOT_CONTROLMODE_RGB,"10"]];
var JOYROBOT_IRKEY=[["1","12"],["2","13"],["3","14"],["4","15"],["5","16"],["6","17"],["7","18"],["8","19"],["9","20"],["0","9"],["A","0"],["B","1"],["C","2"],["D","3"],["+","5"],["-","11"],[Blockly.JOYROBOT_IRKEY_UP,"4"],[Blockly.JOYROBOT_IRKEY_DOWN,"10"],["OK","7"],[Blockly.JOYROBOT_IRKEY_LEFT,"6"],[Blockly.JOYROBOT_IRKEY_RIGHT,"8"]];
var JOYROBOT_ULTRASONICDIRECTION=[[Blockly.JOYROBOT_ULTRASONICDIRECTION_FRONT,"0"],[Blockly.JOYROBOT_ULTRASONICDIRECTION_LEFT,"1"],[Blockly.JOYROBOT_ULTRASONICDIRECTION_RIGHT,"2"]];
var JOYROBOT_IRAVOIDANCEDIRECTION=[[Blockly.JOYROBOT_IRAVOIDANCEDIRECTION_LEFT,"0"],[Blockly.JOYROBOT_IRAVOIDANCEDIRECTION_RIGHT,"1"]];
var JOYROBOT_PS2KEY=[[Blockly.JOYROBOT_PS2KEY_UP,"0x0010"],[Blockly.JOYROBOT_PS2KEY_DOWN,"0x0040"],[Blockly.JOYROBOT_PS2KEY_LEFT,"0x0080"],[Blockly.JOYROBOT_PS2KEY_RIGHT,"0x0020"],["×","0x4000"],["○","0x2000"],["△","0x1000"],["□","0x8000"]];
var JOYROBOT_TRACKINGVALUE=[[Blockly.JOYROBOT_TRACKINGVALUE_BLACK,"0b000"],[Blockly.JOYROBOT_TRACKINGVALUE_WHITE,"0b111"],[Blockly.JOYROBOT_TRACKINGVALUE_CENTER,"0b101"],[Blockly.JOYROBOT_TRACKINGVALUE_RIGHT1,"0b011"],[Blockly.JOYROBOT_TRACKINGVALUE_RIGHT2,"0b001"],[Blockly.JOYROBOT_TRACKINGVALUE_LEFT1,"0b110"],[Blockly.JOYROBOT_TRACKINGVALUE_LEFT2,"0b100"]];
var JOYROBOT_BLUETOOTHKEY=[[Blockly.JOYROBOT_BLUETOOTHKEY_UP,"0"],[Blockly.JOYROBOT_BLUETOOTHKEY_DOWN,"1"],[Blockly.JOYROBOT_BLUETOOTHKEY_LEFT,"2"],[Blockly.JOYROBOT_BLUETOOTHKEY_RIGHT,"3"],[Blockly.JOYROBOT_BLUETOOTHKEY_SPEEDUP,"4"],[Blockly.JOYROBOT_BLUETOOTHKEY_SPEEDDOWN,"5"]];
var JOYROBOT_PHOTOSENSITIVE=[[Blockly.JOYROBOT_PHOTOSENSITIVE_LEFT,"0"],[Blockly.JOYROBOT_PHOTOSENSITIVE_RIGHT,"1"]];
var JOYROBOT_RGBNUMBER=[[Blockly.JOYROBOT_RGBNUMBER_ALL,"0"],[Blockly.JOYROBOT_RGBNUMBER_LEFT,"1"],[Blockly.JOYROBOT_RGBNUMBER_RIGHT,"2"]];
var JOYROBOT_RGBCOLOR=[[Blockly.JOYROBOT_RGBCOLOR_RED,"0xFF0000"],[Blockly.JOYROBOT_RGBCOLOR_GREEN,"0x00FF00"],[Blockly.JOYROBOT_RGBCOLOR_BLUE,"0x0000FF"],[Blockly.JOYROBOT_RGBCOLOR_YELLOW,"0xFFFF00"],[Blockly.JOYROBOT_RGBCOLOR_PURPLE,"0xFF00FF"],[Blockly.JOYROBOT_RGBCOLOR_ORANGE,"0xFF00FF"],[Blockly.JOYROBOT_RGBCOLOR_INDIGO,"0x4b0082"],[Blockly.JOYROBOT_RGBCOLOR_VIOLET,"0x8a2be2"],[Blockly.JOYROBOT_RGBCOLOR_WHITE,"0xFFFFFF"],[Blockly.JOYROBOT_RGBCOLOR_OFF,"0x000000"]];
var JOYROBOT_RGBSTYLE=[[Blockly.JOYROBOT_RGBSTYLE_NONE,"3"],[Blockly.JOYROBOT_RGBSTYLE_BREATHE,"0"],[Blockly.JOYROBOT_RGBSTYLE_ROTATE,"1"],[Blockly.JOYROBOT_RGBSTYLE_FLASH,"2"]];
//第0个图形块的样式,JoyRobot初始化
Blockly.Blocks.hb_setup = {
 init:function(){
	this.setColour(Blockly.Blocks.JoyRobot.HUE);
    this.appendDummyInput("")
	    .appendField(Blockly.JOYROBOT_SETUP)
	    .appendField(new Blockly.FieldImage("../../media/JoyRobot/hb_JoyRobot.png", 45, 38))
	this.setPreviousStatement(false,null);
    this.setNextStatement(true,null);   
	this.setTooltip('');
 }
};

//第一个图形块的样式,小车行驶方向下拉（下拉没有value），速度（输入,有value）
Blockly.Blocks.hb_move = {
  init: function() {
	    this.setColour(Blockly.Blocks.JoyRobot.HUE);
        this.appendDummyInput("")
        .appendField(Blockly.JOYROBOT_MOVE)
		.appendField(new Blockly.FieldImage("../../media/JoyRobot/hb_JoyRobot.png", 45, 38))
        .appendField(new Blockly.FieldDropdown(JOYROBOT_DIRECTION), "Direction")
        .appendField(Blockly.JOYROBOT_SPEED);
	    this.appendValueInput("Speed", Number)
        .setCheck(Number)
        .setAlign(Blockly.ALIGN_RIGHT);
	    this.setPreviousStatement(true, null);
		this.setNextStatement(true, null);
        this.setTooltip('');
  }
};
//第二个图形块的样式,小车操控模式下拉（下拉没有value）
Blockly.Blocks.hb_mode = {
	init:function(){
	    this.setColour(Blockly.Blocks.JoyRobot.HUE);
		this.appendDummyInput("")
			.appendField(Blockly.JOYROBOT_MODE)
		    .appendField(new Blockly.FieldImage("../../media/JoyRobot/hb_JoyRobot.png", 45, 38))
			.appendField(new Blockly.FieldDropdown(JOYROBOT_CONTROLMODE),"Mode")
		this.setPreviousStatement(true, null);
		this.setNextStatement(true, null);
		this.setTooltip('');
		}
};
//第三个图形块的样式,舵机引脚（输入，有value），舵机校正角度（输入，有value）
Blockly.Blocks.hb_servo = {
  init: function() {
    this.setColour(Blockly.Blocks.JoyRobot.HUE);
    this.appendDummyInput("")
        .appendField(Blockly.JOYROBOT_SERVO)
		.appendField(new Blockly.FieldImage("../../media/JoyRobot/hb_servo.png", 45, 38))
    this.appendValueInput("ServoPin", Number)
        .appendField(Blockly.JOYROBOT_SERVOPIN)
        .setCheck(Number)
        .setAlign(Blockly.ALIGN_RIGHT);
    this.appendValueInput("ServoDegree", Number)
        .appendField(Blockly.JOYROBOT_SERVODEGREE)
        .setCheck(Number)
        .setAlign(Blockly.ALIGN_RIGHT);
    this.setPreviousStatement(true, null);
    this.setNextStatement(true, null);
    this.setTooltip('');
  }
};
Blockly.Blocks.hb_servoangle = {
  init: function() {
    this.setColour(Blockly.Blocks.JoyRobot.HUE);
    this.appendDummyInput("")
        .appendField(Blockly.JOYROBOT_SERVO)
		.appendField(new Blockly.FieldImage("../../media/JoyRobot/hb_servo.png", 45, 38))
    this.appendValueInput("ServoAngle", Number)
        .appendField(Blockly.JOYROBOT_SERVOANGLE)
        .setCheck(Number)
        .setAlign(Blockly.ALIGN_RIGHT);
    this.setPreviousStatement(true, null);
    this.setNextStatement(true, null);
    this.setTooltip('');
  }
};
//第四个图形块的样式,四个电机引脚（输入，有value）
Blockly.Blocks.hb_motor = {
  init: function() {
    this.setColour(Blockly.Blocks.JoyRobot.HUE);
    this.appendDummyInput("")
        .appendField(Blockly.JOYROBOT_MOTORPIN)
		.appendField(new Blockly.FieldImage("../../media/JoyRobot/hb_motor.png", 45, 38))
    this.appendValueInput("LeftNegativeValue", Number)
        .appendField(Blockly.JOYROBOT_LEFTNEGATIVEPIN)
        .setCheck(Number)
        .setAlign(Blockly.ALIGN_RIGHT);
    this.appendValueInput("LeftPositiveValue", Number)
        .appendField(Blockly.JOYROBOT_LEFTPOSITIVEPIN)
        .setCheck(Number)
        .setAlign(Blockly.ALIGN_RIGHT);
	this.appendValueInput("RightNegativeValue", Number)
        .appendField(Blockly.JOYROBOT_RIGHTNEGATIVEPIN)
        .setCheck(Number)
        .setAlign(Blockly.ALIGN_RIGHT);
    this.appendValueInput("RightPositiveValue", Number)
        .appendField(Blockly.JOYROBOT_RIGHTPOSITIVEPIN)
        .setCheck(Number)
        .setAlign(Blockly.ALIGN_RIGHT);
    this.setPreviousStatement(true, null);
    this.setNextStatement(true, null);
    this.setTooltip('');
  }
};
//第五个图形块的样式,转弯角度（输入，有value），速度（输入，有value）
Blockly.Blocks.hb_turn = {
  init: function() {
    this.setColour(Blockly.Blocks.JoyRobot.HUE);
    this.appendDummyInput("")
        .appendField(Blockly.JOYROBOT_TURN)
		.appendField(new Blockly.FieldImage("../../media/JoyRobot/hb_JoyRobot.png", 45, 38))
    this.appendValueInput("TurnAngle", Number)
        .appendField(Blockly.JOYROBOT_TURNANGLE)
        .setCheck(Number)
        .setAlign(Blockly.ALIGN_RIGHT);
    this.appendValueInput("Speed", Number)
        .appendField(Blockly.JOYROBOT_SPEED)
        .setCheck(Number)
        .setAlign(Blockly.ALIGN_RIGHT);
    this.setPreviousStatement(true, null);
    this.setNextStatement(true, null);
    this.setTooltip('');
  }
};

//设置速度或者角度
Blockly.Blocks.hb_SetSpeedOrDegree = {
  init: function() {
    this.setColour(100);
	this.appendDummyInput("")
	.appendField(Blockly.HB_SetSpeedOrDegree);
	
	this.appendDummyInput("")
	.appendField(new Blockly.FieldDropdown([
		["行驶角度","Drive"],
		["速度","SetSpeed"],
		]), "SetRobotSpeedOrDegree");
    
	this.appendValueInput("SpeedOrDegree", Number)
	this.setInputsInline(true);
    this.setPreviousStatement(true, null);
    this.setNextStatement(true, null);
    this.setTooltip('');
  }
};

//第六个图形块的样式,加速
Blockly.Blocks.hb_speedup = {
 init:function(){
	 this.setColour(Blockly.Blocks.JoyRobot.HUE);
	 this.appendDummyInput("")        
		 .appendField(new Blockly.FieldImage("../../media/JoyRobot/hb_JoyRobot.png", 45, 38))
		 .appendField(Blockly.JOYROBOT_SPEEDUP)
	this.setPreviousStatement(true, null);
    this.setNextStatement(true, null);
    this.setTooltip('');
 }
};
//第七个图形块的样式,加速
Blockly.Blocks.hb_speeddown = {
 init:function(){
	 this.setColour(Blockly.Blocks.JoyRobot.HUE);
	 this.appendDummyInput("")        
		 .appendField(new Blockly.FieldImage("../../media/JoyRobot/hb_JoyRobot.png", 45, 38))
		 .appendField(Blockly.JOYROBOT_SPEEDDOWN)
	this.setPreviousStatement(true, null);
    this.setNextStatement(true, null);
    this.setTooltip('');
 }
};
//获取当前速度
Blockly.Blocks.hb_getcurrentspeed = {
  init: function() {
    this.setColour(Blockly.Blocks.JoyRobot.HUE);
    this.appendDummyInput("")
        .appendField(Blockly.JOYROBOT_GETCURRENTSPEED)
		.appendField(new Blockly.FieldImage("../../media/JoyRobot/hb_JoyRobot.png", 45, 38))
    this.setOutput(true, Number);
    this.setTooltip('');
  }
};
//第八个图形块的样式 红外接收初始化
Blockly.Blocks.hb_irReceive = {
  init: function() {
    this.setColour(Blockly.Blocks.JoyRobot.HUE);
    this.appendDummyInput("")
        .appendField(Blockly.JOYROBOT_IRRECEIVEPIN)
		.appendField(new Blockly.FieldImage("../../media/JoyRobot/hb_irremote.png", 45, 38))
    this.setPreviousStatement(true, null);
    this.setNextStatement(true, null);
    this.setTooltip('');
  }
};
//第八.2个图形块的样式 红外遥控按键是否按下（返回boolean）
Blockly.Blocks.hb_irKeyPressed = {
  init: function() {
    this.setColour(Blockly.Blocks.JoyRobot.HUE);
    this.appendDummyInput("")
        .appendField(Blockly.JOYROBOT_IRKEYPRESSED)
		.appendField(new Blockly.FieldImage("../../media/JoyRobot/hb_irremote.png", 45, 38))
    this.setOutput(true, Boolean);
    this.setTooltip('');
  }
};
//第九个图形块的样式 红外遥控按键（下拉，返回boolean）
Blockly.Blocks.hb_irKeyPress = {
  init: function() {
    this.setColour(Blockly.Blocks.JoyRobot.HUE);
    this.appendDummyInput("")
        .appendField(Blockly.JOYROBOT_IRKEYPRESS)
		.appendField(new Blockly.FieldImage("../../media/JoyRobot/hb_irremote.png", 45, 38))
		.appendField(new Blockly.FieldDropdown(JOYROBOT_IRKEY), "Irkey")
    this.setOutput(true, Number);
    this.setTooltip('');
  }
};
//第十个图形块的样式 超声波模块两个引脚,rgb引脚（输入 有value）
Blockly.Blocks.hb_ultrasonicpin = {
  init: function() {
    this.setColour(Blockly.Blocks.JoyRobot.HUE);
    this.appendDummyInput("")
        .appendField(Blockly.JOYROBOT_ULTRASONICPIN)
		.appendField(new Blockly.FieldImage("../../media/JoyRobot/hb_ultrasonic.png", 45, 38))
    this.appendValueInput("SingPin", Number)
        .appendField(Blockly.JOYROBOT_SING)
        .setCheck(Number)
        .setAlign(Blockly.ALIGN_RIGHT);
    this.appendValueInput("RGBPin", Number)
        .appendField(Blockly.JOYROBOT_RGB)
        .setCheck(Number)
        .setAlign(Blockly.ALIGN_RIGHT);
    this.setPreviousStatement(true, null);
    this.setNextStatement(true, null);
    this.setTooltip('');
  }
};
//第十一个图形块的样式(setOutput) 超声波测距（下拉，前，左，右）
Blockly.Blocks.hb_readUltrasonicDistance = {
  init: function() {
    this.setColour(Blockly.Blocks.JoyRobot.HUE);
    this.appendDummyInput("")
        .appendField(Blockly.JOYROBOT_READULTRASONICDISTANCE)
		.appendField(new Blockly.FieldImage("../../media/JoyRobot/hb_ultrasonic.png", 45, 38))
		.appendField(new Blockly.FieldDropdown(JOYROBOT_ULTRASONICDIRECTION), "UltrasonicDirection")
    this.setOutput(true, Number);
    this.setTooltip('');
  }
};
//设置RGB灯颜色（下拉，红，绿，蓝，黄，紫，白，黑）
Blockly.Blocks.hb_RGB = {
  init: function(){
	 this.setColour(Blockly.Blocks.JoyRobot.HUE);
	 this.appendDummyInput("")
         .appendField(Blockly.JOYROBOT_SETRGB)
	 	 .appendField(new Blockly.FieldImage("../../media/JoyRobot/hb_ultrasonic.png", 45, 38))
         .appendField(new Blockly.FieldDropdown(JOYROBOT_RGBNUMBER), "RGB")
	     .appendField(Blockly.JOYROBOT_RGBCOLOUR)
		 .appendField(new Blockly.FieldDropdown(JOYROBOT_RGBCOLOR), "RGBCOLOR")
		 .appendField(Blockly.JOYROBOT_SETRGBSTYLE)
         .appendField(new Blockly.FieldDropdown(JOYROBOT_RGBSTYLE), "RGBSTYLE")
	this.setPreviousStatement(true, null);
    this.setNextStatement(true, null);
 	
	}	
};
//第十二个图形块的样式 红外避障模块两个引脚(输入，有value)    field的name不确定使NUM待检测
Blockly.Blocks.hb_irAvoidance = {
  init: function() {
    this.setColour(Blockly.Blocks.JoyRobot.HUE);
    this.appendDummyInput("")
        .appendField(Blockly.JOYROBOT_IRAVOIDANCEPIN)
		.appendField(new Blockly.FieldImage("../../media/JoyRobot/hb_lightfind.png", 45, 38))
    this.appendValueInput("LeftPin", Number)
        .appendField(Blockly.JOYROBOT_LEFTPIN)
        .setCheck(Number)
        .setAlign(Blockly.ALIGN_RIGHT);
    this.appendValueInput("RightPin", Number)
        .appendField(Blockly.JOYROBOT_RIGHTPIN)
        .setCheck(Number)
        .setAlign(Blockly.ALIGN_RIGHT);
    this.setPreviousStatement(true, null);
    this.setNextStatement(true, null);
    this.setTooltip('');
  }
};
//追光模块
Blockly.Blocks.hb_photosensitivePin = {
  init: function() {
    this.setColour(Blockly.Blocks.JoyRobot.HUE);
    this.appendDummyInput("")
        .appendField(Blockly.JOYROBOT_PHOTOSENSITIVEPIN)
		.appendField(new Blockly.FieldImage("../../media/JoyRobot/hb_lightfind.png", 45, 38))
    this.appendValueInput("LeftPin", Number)
        .appendField(Blockly.JOYROBOT_LEFTPIN)
        .setCheck(Number)
        .setAlign(Blockly.ALIGN_RIGHT);
    this.appendValueInput("RightPin", Number)
        .appendField(Blockly.JOYROBOT_RIGHTPIN)
        .setCheck(Number)
        .setAlign(Blockly.ALIGN_RIGHT);
    this.setPreviousStatement(true, null);
    this.setNextStatement(true, null);
    this.setTooltip('');
  }
};
//左右光弱度模块
Blockly.Blocks.hb_getPhotosensitive = {
  init: function() {
    this.setColour(Blockly.Blocks.JoyRobot.HUE);
    this.appendDummyInput("")
        .appendField(Blockly.JOYROBOT_GETPHOTOSENSITIVE)
		.appendField(new Blockly.FieldImage("../../media/JoyRobot/hb_lightfind.png", 45, 38))
		.appendField(new Blockly.FieldDropdown(JOYROBOT_PHOTOSENSITIVE), "Photosensitive")
    this.setOutput(true, Number);
    this.setTooltip('');
  }
};
//第十三个图形块的样式 红外避障测距（下拉，左，右）
Blockly.Blocks.hb_readIrAvoidanceDistance = {
  init: function() {
    this.setColour(Blockly.Blocks.JoyRobot.HUE);
    this.appendDummyInput("")
        .appendField(Blockly.JOYROBOT_READIRAVOIDANCEDISTANCE)
		.appendField(new Blockly.FieldImage("../../media/JoyRobot/hb_lightfind.png", 45, 38))
		.appendField(new Blockly.FieldDropdown(JOYROBOT_IRAVOIDANCEDIRECTION), "IrAvoidanceDirection")
    this.setOutput(true, Number);
    this.setTooltip('');
  }
};
//第十四个图形块的样式 PS2模块四个引脚(输入，有value)
Blockly.Blocks.hb_PS2Pin = {
  init: function() {
    this.setColour(Blockly.Blocks.JoyRobot.HUE);
    this.appendDummyInput("")
        .appendField(Blockly.JOYROBOT_PS2PIN)
		.appendField(new Blockly.FieldImage("../../media/JoyRobot/hb_ps2.png", 45, 38))
    this.appendValueInput("CLKPin", Number)
        .appendField(Blockly.JOYROBOT_CLKPIN)
        .setCheck(Number)
        .setAlign(Blockly.ALIGN_RIGHT);
    this.appendValueInput("CMDPin", Number)
        .appendField(Blockly.JOYROBOT_CMDPIN)
        .setCheck(Number)
        .setAlign(Blockly.ALIGN_RIGHT);
	this.appendValueInput("ATTPin", Number)
        .appendField(Blockly.JOYROBOT_ATTPIN)
        .setCheck(Number)
        .setAlign(Blockly.ALIGN_RIGHT);
    this.appendValueInput("DATPin", Number)
        .appendField(Blockly.JOYROBOT_DATPIN)
        .setCheck(Number)
        .setAlign(Blockly.ALIGN_RIGHT);
    this.setPreviousStatement(true, null);
    this.setNextStatement(true, null);
    this.setTooltip('');
  }
}; 
//第十五个图形块的样式 定义PS2摇杆震动值
Blockly.Blocks.hb_varPS2vibrate = {
 init:function(){
	this.setColour(Blockly.Blocks.JoyRobot.HUE);
    this.appendDummyInput("")
	    .appendField(Blockly.JOYROBOT_VARPS2VIBRATE)
	    .appendField(new Blockly.FieldImage("../../media/JoyRobot/hb_ps2.png", 45, 38))
	this.setPreviousStatement(true,null);
    this.setNextStatement(true,null);   
	this.setTooltip('');
 }
};
//第十六个图形块的样式 设置PS2摇杆震动值
Blockly.Blocks.hb_setPS2vibrate = {
 init:function(){
	this.setColour(Blockly.Blocks.JoyRobot.HUE);
    this.appendDummyInput("")
	    .appendField(Blockly.JOYROBOT_SETPS2VIBRATE)
	    .appendField(new Blockly.FieldImage("../../media/JoyRobot/hb_ps2.png", 45, 38))
	this.setPreviousStatement(true,null);
    this.setNextStatement(true,null);   
	this.setTooltip('');
 }
};
//第十七个图形块的样式 PS2键被按下（返回boolean）
Blockly.Blocks.hb_PS2KeyPressed = {
  init:function(){
	this.setColour(Blockly.Blocks.JoyRobot.HUE);
	this.appendDummyInput("")
	    .appendField(Blockly.JOYROBOT_PS2KEYPRESSED)
	    .appendField(new Blockly.FieldImage("../../media/JoyRobot/hb_ps2.png", 45, 38))
	this.setOutput(true, Boolean);
	this.setTooltip('');
  }
};
//第十八个图形块的样式 PS2键被按下（下拉）
Blockly.Blocks.hb_WhichPS2KeyPressed = {
  init:function(){
	this.setColour(Blockly.Blocks.JoyRobot.HUE);
	this.appendDummyInput("")
	    .appendField(Blockly.JOYROBOT_WHICHPS2KEYPRESSED)
	    .appendField(new Blockly.FieldImage("../../media/JoyRobot/hb_ps2.png", 45, 38))
	    .appendField(new Blockly.FieldDropdown(JOYROBOT_PS2KEY), "PS2Key")
	this.setOutput(true, Boolean);
	this.setTooltip('');
  }
};
//第十九个图形块的样式 红外循迹模块三个引脚(输入，有value)
Blockly.Blocks.hb_IrTrackingPin = {
  init: function() {
    this.setColour(Blockly.Blocks.JoyRobot.HUE);
    this.appendDummyInput("")
        .appendField(Blockly.JOYROBOT_IRTRACKINGPIN)
		.appendField(new Blockly.FieldImage("../../media/JoyRobot/hb_irtracking.png", 45, 38))
    this.appendValueInput("IrTrackingLeftPin", Number)
        .appendField(Blockly.JOYROBOT_IRTRACKINGLEFTPIN)
        .setCheck(Number)
        .setAlign(Blockly.ALIGN_RIGHT);
    this.appendValueInput("IrTrackingMidPin", Number)
        .appendField(Blockly.JOYROBOT_IRTRACKINGMIDPIN)
        .setCheck(Number)
        .setAlign(Blockly.ALIGN_RIGHT);
	this.appendValueInput("IrTrackingRightPin", Number)
        .appendField(Blockly.JOYROBOT_IRTRACKINGRIGHTPIN)
        .setCheck(Number)
        .setAlign(Blockly.ALIGN_RIGHT);
    this.setPreviousStatement(true, null);
    this.setNextStatement(true, null);
    this.setTooltip('');
  }
};
//第二十个图形块的样式 读取循迹状态（下拉）
Blockly.Blocks.hb_readTrackingValue = {
  init:function(){
	this.setColour(Blockly.Blocks.JoyRobot.HUE);
	this.appendDummyInput("")
	    .appendField(Blockly.JOYROBOT_READTRACKINGVALUE)
	    .appendField(new Blockly.FieldImage("../../media/JoyRobot/hb_irtracking.png", 45, 38))
	    //.appendField(new Blockly.FieldDropdown(JOYROBOT_TRACKINGVALUE), "TrackingValue")
	this.setOutput(true, Boolean);
	this.setTooltip('');
  }
};
Blockly.Blocks.hb_readTrackingValues = {
  init:function(){
	this.setColour(Blockly.Blocks.JoyRobot.HUE);
	this.appendDummyInput("")
	    .appendField(Blockly.JOYROBOT_READTRACKINGVALUE)
	    .appendField(new Blockly.FieldImage("../../media/JoyRobot/hb_irtracking.png", 45, 38))
	    .appendField(new Blockly.FieldDropdown(JOYROBOT_TRACKINGVALUE), "TrackingValue")
	this.setOutput(true, Boolean);
	this.setTooltip('');
  }
};
//第二十一个图形块的样式 定义一个保存上一次循迹状态的变量
Blockly.Blocks.hb_setByteOld = {
 init:function(){
	this.setColour(Blockly.Blocks.JoyRobot.HUE);
    this.appendDummyInput("")
	    .appendField(Blockly.JOYROBOT_SETBYTEOLD)
	    .appendField(new Blockly.FieldImage("../../media/JoyRobot/hb_irtracking.png", 45, 38))
	this.setPreviousStatement(true,null);
    this.setNextStatement(true,null);   
	this.setTooltip('');
 }
};
//第二十二个图形块的样式 当前循迹状态（下拉）
Blockly.Blocks.hb_recentTrackingValue = {
  init:function(){
	this.setColour(Blockly.Blocks.JoyRobot.HUE);
	this.appendDummyInput("")
	    .appendField(Blockly.JOYROBOT_RECENTTRACKINGVALUE)
	    .appendField(new Blockly.FieldImage("../../media/JoyRobot/hb_irtracking.png", 45, 38))
	    .appendField(new Blockly.FieldDropdown(JOYROBOT_TRACKINGVALUE), "TrackingValue")
	this.setOutput(true, Boolean);
	this.setTooltip('');
  }
};
//第二十三个图形块的样式 清除上一次循迹状态
Blockly.Blocks.hb_cleanLastTrackingValue = {
 init:function(){
	this.setColour(Blockly.Blocks.JoyRobot.HUE);
    this.appendDummyInput("")
	    .appendField(Blockly.JOYROBOT_CLEANLASTTRACKINGVALUE)
	    .appendField(new Blockly.FieldImage("../../media/JoyRobot/hb_irtracking.png", 45, 38))
	this.setPreviousStatement(true,null);
    this.setNextStatement(true,null);   
	this.setTooltip('');
 }
};
//第二十四个图形块的样式 当前循迹状态不是全白
Blockly.Blocks.hb_recentTrackingValueIsNotWhite = {
 init:function(){
	this.setColour(Blockly.Blocks.JoyRobot.HUE);
    this.appendDummyInput("")
	    .appendField(Blockly.JOYROBOT_RECENTTRACKINGVALUEISNOTWHITE)
	    .appendField(new Blockly.FieldImage("../../media/JoyRobot/hb_irtracking.png", 45, 38))
	this.setOutput(true,Boolean);  
	this.setTooltip('');
 }
};
//第二十五个图形块的样式 重置上一次循迹状态
Blockly.Blocks.hb_resetLastTrackingValue = {
 init:function(){
	this.setColour(Blockly.Blocks.JoyRobot.HUE);
    this.appendDummyInput("")
	    .appendField(Blockly.JOYROBOT_RESETLASTTRACKINGVALUE)
	    .appendField(new Blockly.FieldImage("../../media/JoyRobot/hb_irtracking.png", 45, 38))
		.appendField(new Blockly.FieldDropdown(JOYROBOT_TRACKINGVALUE), "TrackingValue")
	this.setPreviousStatement(true,null);
    this.setNextStatement(true,null);   
	this.setTooltip('');
 }
};
//第二十六个图形块的样式 接收蓝牙数据
Blockly.Blocks.hb_receiveBluetoothData = {
 init:function(){
	this.setColour(Blockly.Blocks.JoyRobot.HUE);
    this.appendDummyInput("")
	    .appendField(Blockly.JOYROBOT_RECEIVEBLUETOOTHDATA)
	    .appendField(new Blockly.FieldImage("../../media/JoyRobot/hb_bluetooth.png", 45, 38))
	this.setPreviousStatement(true,null);
    this.setNextStatement(true,null);   
	this.setTooltip('');
 }
};
//第二十七个图形块的样式 接收到了蓝牙数据
Blockly.Blocks.hb_receivedBluetoothData = {
 init:function(){
	this.setColour(Blockly.Blocks.JoyRobot.HUE);
    this.appendDummyInput("")
	    .appendField(Blockly.JOYROBOT_RECEIVEDBLUETOOTHDATA)
	    .appendField(new Blockly.FieldImage("../../media/JoyRobot/hb_bluetooth.png", 45, 38))
	this.setOutput(true,Boolean);  
	this.setTooltip('');
 }
};
//第二十八个图形块的样式 蓝牙操控键按下（下拉）
Blockly.Blocks.hb_bluetoothKeyPressed = {
 init:function(){
	this.setColour(Blockly.Blocks.JoyRobot.HUE);
    this.appendDummyInput("")
	    .appendField(Blockly.JOYROBOT_BLUETOOTHKEYPRESSED)
	    .appendField(new Blockly.FieldImage("../../media/JoyRobot/hb_bluetooth.png", 45, 38))
		.appendField(new Blockly.FieldDropdown(JOYROBOT_BLUETOOTHKEY), "BluetoothKey")
	this.setOutput(true,Boolean);  
	this.setTooltip('');
 }
};

Blockly.Blocks.hb_firepin = {
          init:function(){
          this.setColour(Blockly.Blocks.JoyRobot.HUE);
          this.appendDummyInput("")
              .appendField(Blockly.JOYROBOT_FIRE)
			   this.appendDummyInput("")
              .appendField(Blockly.JOYROBOT_FIRELEFT)
              .appendField(new Blockly.FieldDropdown([
                ['0', "0"],
                  ['1', "1"],
                  ['2', "2"],
                  ['3', "3"],
                  ['4', "4"],
                  ['5', "5"],
                  ['6', "6"],
                  ['7', "7"],
                  ['8', "8"],
                  ['9', "9"],
                  ['10', "10"],
                  ['11', "11"],
                  ['12', "12"],
                  ['13', "13"],
                  ['A0', "A0"],
                  ['A1', "A1"],
                  ['A2', "A2"],
                  ['A3', "A3"],
                  ['A4', "A4"],
                  ['A5', "A5"],
                ]),"FIRELEFT")
				.appendField(Blockly.JOYROBOT_FIRERIGHT)
              .appendField(new Blockly.FieldDropdown([
                ['0', "0"],
                  ['1', "1"],
                  ['2', "2"],
                  ['3', "3"],
                  ['4', "4"],
                  ['5', "5"],
                  ['6', "6"],
                  ['7', "7"],
                  ['8', "8"],
                  ['9', "9"],
                  ['10', "10"],
                  ['11', "11"],
                  ['12', "12"],
                  ['13', "13"],
                  ['A0', "A0"],
                  ['A1', "A1"],
                  ['A2', "A2"],
                  ['A3', "A3"],
                  ['A4', "A4"],
                  ['A5', "A5"],
                ]),"FIRERIGHT")
				 this.appendDummyInput("")
              .appendField(Blockly.JOYROBOT_SOUND)
              .appendField(new Blockly.FieldDropdown([
                ['0', "0"],
                  ['1', "1"],
                  ['2', "2"],
                  ['3', "3"],
                  ['4', "4"],
                  ['5', "5"],
                  ['6', "6"],
                  ['7', "7"],
                  ['8', "8"],
                  ['9', "9"],
                  ['10', "10"],
                  ['11', "11"],
                  ['12', "12"],
                  ['13', "13"],
                  ['A0', "A0"],
                  ['A1', "A1"],
                  ['A2', "A2"],
                  ['A3', "A3"],
                  ['A4', "A4"],
                  ['A5', "A5"],
                ]),"SOUND")
			  this.setInputsInline(true);
          this.setPreviousStatement(true,null);
            this.setNextStatement(true,null);
          this.setTooltip('');
          }
        };

//风扇引脚
		Blockly.Blocks.hb_fun = {
          init:function(){
          this.setColour(Blockly.Blocks.JoyRobot.HUE);
          this.appendDummyInput("")
              .appendField(Blockly.JOYROBOT_FUN)
              .appendField(new Blockly.FieldDropdown([
                ['0', "0"],
                  ['1', "1"],
                  ['2', "2"],
                  ['3', "3"],
                  ['4', "4"],
                  ['5', "5"],
                  ['6', "6"],
                  ['7', "7"],
                  ['8', "8"],
                  ['9', "9"],
                  ['10', "10"],
                  ['11', "11"],
                  ['12', "12"],
                  ['13', "13"],
                  ['A0', "A0"],
                  ['A1', "A1"],
                  ['A2', "A2"],
                  ['A3', "A3"],
                  ['A4', "A4"],
                  ['A5', "A5"],
                ]),"FUN")
          this.setPreviousStatement(true,null);
            this.setNextStatement(true,null);
          this.setTooltip('');
          }
        };
//左或右，有无火源 
		Blockly.Blocks.hb_firefun = {
          init:function(){
          this.setColour(Blockly.Blocks.JoyRobot.HUE);
          this.appendDummyInput("")
              .appendField(new Blockly.FieldDropdown([
                  [Blockly.JOYROBOT_FIREFUNLEFT, "A4"],
                  [Blockly.JOYROBOT_FIREFUNRIGHT, "A3"],
                ]),"FIREFUNDIRECTION")
              .appendField(new Blockly.FieldDropdown([
                  [Blockly.JOYROBOT_HAVEFIRE, "0"],
                  [Blockly.JOYROBOT_HAVENOFIRE, "1"],
                ]),"ISFIRE")
         this.setOutput(true, Boolean);
    this.setTooltip('');
          }
        };
//开关风扇
		Blockly.Blocks.hb_openfirefun
		= {
          init:function(){
          this.setColour(Blockly.Blocks.JoyRobot.HUE);
          this.appendDummyInput("")
              .appendField(Blockly.JOYROBOT_OPENFUN)
              .appendField(new Blockly.FieldDropdown([
               [Blockly.JOYROBOT_OPENFUNS, "1"],
                  [Blockly.JOYROBOT_CLOSEFUNS, "0"],
                ]),"FUNSS")
          this.setPreviousStatement(true,null);
            this.setNextStatement(true,null);
          this.setTooltip('');
          }
		};
		
//初始化nRF24L01+
Blockly.Blocks.hb_InitNrf = {
 init:function(){
	this.setColour(100);
    this.appendDummyInput("")
	    .appendField(Blockly.HB_InitNrf)
	this.appendValueInput("Raddress", String)
		.setCheck([String, Number])
		.setAlign(Blockly.ALIGN_RIGHT)
		.appendField(Blockly.Raddress)
	this.setPreviousStatement(true,null);
    this.setNextStatement(true,null);   
	this.setTooltip('');
 }
};
//nRF24L01+是否接收到数据
Blockly.Blocks.hb_ReceivedNrf24L01Data = {
  init:function(){
	this.setColour(100);
	this.appendDummyInput("")
	    .appendField(Blockly.HB_ReceivedNrf24L01Data)
	this.setOutput(true, Boolean);
	this.setTooltip('');
  }
};
// 读取nRF24L01+无线手柄数据
Blockly.Blocks.hb_ReadNrf24L01Data = {
 init:function(){
	this.setColour(100);
    this.appendDummyInput("")
	    .appendField(Blockly.HB_ReadNrf24L01Data)
	this.setPreviousStatement(true, null);
    this.setNextStatement(true, null);
    this.setTooltip('');
  }
};
//解析数据
Blockly.Blocks.hb_ParsingData = {
  init:function(){
	this.setColour(100);
	this.appendDummyInput("")
	    .appendField(Blockly.HB_ParsingData)
	this.setOutput(true, Boolean);
	this.setTooltip('');
  }
};
//判断接收数据类型
Blockly.Blocks.hb_ReadDataTyps = {
   init: function() {
    this.setColour(100);
    this.appendDummyInput("")   
		.appendField(Blockly.HB_ReadDataTyps)    
		.appendField(new Blockly.FieldDropdown([
		["Degree","E_ROBOT_CONTROL_DIRECTION"],
		["Speed","E_ROBOT_CONTROL_SPEED"],
		["Button","E_BUTTON"],
		]), "ReadHandleData");
	this.setOutput(true, Boolean);
	this.setInputsInline(true);
  } 
};
// 读取角度
Blockly.Blocks.hb_ReadDegreeData = {
  init: function() {
    this.setColour(100);
    this.appendDummyInput("")
	    .appendField(Blockly.HB_ReadDegreeData)
    this.setOutput(true, Number);
	this.setInputsInline(true);
  }
};
//读取速度
Blockly.Blocks.hb_ReadSpeedData = {
  init: function() {
    this.setColour(100);
    this.appendDummyInput("")
	    .appendField(Blockly.HB_ReadSpeedData)
    this.setOutput(true, Number);
	this.setInputsInline(true);
  }
};
//判断按键
Blockly.Blocks.hb_JudgeButton = {
   init: function() {
    this.setColour(100);
    this.appendDummyInput("")    
		.appendField(Blockly.HB_JudgeButton)	
		.appendField(new Blockly.FieldDropdown([
		["BT_PAD_UP","BT_PAD_UP"],
		["BT_PAD_DOWN","BT_PAD_DOWN"],
		["BT_PAD_LEFT","BT_PAD_LEFT"],
		["BT_PAD_RIGHT","BT_PAD_RIGHT"],
		["BT_L","BT_L"],
		["BT_R","BT_R"],
		["BT_SELECT","BT_SELECT"],
		["BT_MODE","BT_MODE"],
		["BT_ENTER","BT_ENTER"],
		]), "ReadHandleButton");
	this.setOutput(true, Boolean);
	this.setInputsInline(true);
  } 
};
